﻿using System;
using System.Collections.Generic;

using System.Text;
using NHibernate;
using System.Web;
namespace Ecreate.Popedom
{
    public class Utility
    {
        public static string SessionItemName = "hib_session_name";

        public static ISessionFactory getSessionFactory()
        {
            return Ecreate.Data.FactoryDBEngine.getHibernateService().getSessionFactory();
        }
        public static ISession getSession()
        {

            object obj2 = HttpContext.Current.Items[SessionItemName];
            if (obj2 == null)
            {
                ISession session = getSessionFactory().OpenSession();
                HttpContext.Current.Items.Add(SessionItemName, session);
                obj2 = session;
            }
            return (ISession)obj2;

        }
        public static void DeleteModel(object o)
        {
            ISession session = getSession();
            session.Transaction.Begin();
            session.Clear();
            session.Delete(o);
            session.Transaction.Commit();
        }


        public static IList<T> QueryForList<T>(string hql)
        {
            NHibernate.ISession s = Utility.getSession();
            return s.CreateQuery(hql).List<T>();
        }
    }

   
}
